import 'package:fluent_ui/fluent_ui.dart';

import '../theme.dart';
///@ClassName: gyy_theme
/// @Author: guoyangyang
///@Date: 2022 11/3/22 10:39 AM
///@Description:  自定义的样式

const fontSize = 14.0;

EdgeInsetsGeometry paddingH15 = const EdgeInsets.symmetric(horizontal: 15);
EdgeInsetsGeometry paddingH20 = const EdgeInsets.symmetric(horizontal: 20);
const delayedDuration =  Duration(milliseconds: 400);

const backIcon =  Icon(
FluentIcons.back,
size: fontSize,
);
const forwardIcon =  Icon(
  FluentIcons.forward,
  size: fontSize,
);
const downIcon =  Icon(
  FluentIcons.chevron_down,
  color: Colors.white,
  size: fontSize,
);
const upIcon =  Icon(
  FluentIcons.chevron_up,
  color: Colors.white,
  size: fontSize,
);

TextStyle whiteStyle  = const TextStyle(color: Colors.white);
TextStyle blackStyle  = const TextStyle(color: Colors.black);

//响应主题变化, 需要写成方法，而不是一个对象
TextStyle accentTextStyle() => TextStyle(
fontFamily: 'Arial',
fontSize: fontSize,
color: AppTheme.accentColor,
);

TextStyle readOnlyTextStyle() => TextStyle(
  fontFamily: 'Arial',
  fontSize: fontSize,
  color: AppTheme.accentColor.withOpacity(0.5),
);

const TextStyle headerTextStyle =  TextStyle(
fontSize: fontSize,
color: Colors.black,
fontWeight: FontWeight.w600,
);

BoxDecoration boxDecoration = BoxDecoration(
  border: Border.all(width: 1.5, color: Colors.black),
);

/// The default constraints for [ContentDialog]
const contentDialogConstraints = BoxConstraints(
  maxWidth: 1000.0,
  maxHeight: 800.0,
);

const spacer = Spacer();
const pageRow = Text("Rows per page:");

const sizeBox = SizedBox();
const sizeBoxV1 = SizedBox(
  height: 1,
);
const sizeBoxV5 = SizedBox(
  height: 5,
);
const sizeBoxV10 = SizedBox(
  height: 10,
);
const sizeBoxH1 = SizedBox(
  width: 1,
);
const sizeBoxH5 = SizedBox(
  width: 5,
);
const sizeBoxH10 = SizedBox(
  width: 10,
);

//title在上方的TextBox
class GyyTextBox extends TextBox {
  const GyyTextBox({
    Key? key,
    header,
    headerStyle = headerTextStyle,
    placeholder = '请输入',
    placeholderStyle = const TextStyle(
      fontSize: 12,
      color: Colors.black,
      fontWeight: FontWeight.normal,
    ),
    readOnly = false,
    controller,
    initialValue,
    onChanged

  }) : super(key: key, header: header, headerStyle: headerStyle, placeholder: placeholder, placeholderStyle: placeholderStyle,
      readOnly: readOnly, controller: controller, initialValue: initialValue, onChanged: onChanged);

  @override
  TextStyle? get style => readOnly? readOnlyTextStyle() : accentTextStyle();
}

//title在上方的TextBox
class GyyTextBoxHint extends StatelessWidget {
  final String? hint;
  final double minHeight;
  final double width;
  final TextEditingController controller;

  const GyyTextBoxHint(this.hint, this.width, this.minHeight, this.controller,
      {Key? key})
      : super(key: key);

  @override
  Widget build(BuildContext context) {
    return SizedBox(
      child: Container(
          decoration: boxDecoration,
          child: TextBox(
            maxLines: null,
            expands: true,
            highlightColor: Colors.transparent,
            unfocusedColor: Colors.transparent,
            placeholder: hint,
            minHeight: minHeight - 4,
            placeholderStyle: const TextStyle(
              fontSize: 10,
              color: Color(0xFF484644),
              fontWeight: FontWeight.normal,
            ),
          )),
      width: width,
      height: minHeight,
    );
  }
}

//无边框的输入框
class GyyTextInput extends StatelessWidget {
  final String hint;
  final bool readOnly;
  final TextEditingController controller;
  final ValueChanged<String>? onSubmitted;

  const GyyTextInput(this.hint, this.controller, {Key? key, this.readOnly = false, this.onSubmitted}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Container(
        decoration: BoxDecoration(
          border: Border.all(width: 1.5, color: Colors.black),
        ),
        child: Row(
          children: [
            Container(
              child: Text(
                hint,
              ),
            ),
            Expanded(
                child: TextBox(
                  readOnly: readOnly,
                    controller: controller,
                    highlightColor: Colors.transparent,
                    unfocusedColor: Colors.transparent,
                    onSubmitted: onSubmitted,
                    style: readOnly ? readOnlyTextStyle() : accentTextStyle()))
          ],
        ));
  }
}

//点击选中的button
class GyyToggleButton extends ToggleButton {
  final String text;

  const GyyToggleButton(this.text, checked, onChanged, {Key? key})
      : super(key: key, checked: checked, onChanged: onChanged);

  @override
  Widget build(BuildContext context) {
    return Container(
      decoration: BoxDecoration(
        border: checked
            ? Border.all(color: AppTheme.accentColor, width: 2)
            : Border.all(color: Colors.black, width: 2),
      ),
      child: ToggleButton(
          style: ToggleButtonThemeData(
            checkedButtonStyle: ButtonStyle(
              backgroundColor: ButtonState.resolveWith(
                (states) => ButtonThemeData.checkedInputColor(
                  FluentTheme.of(context),
                  states,
                ),
              ),
              shape: ButtonState.all(const RoundedRectangleBorder()),
              foregroundColor: ButtonState.resolveWith(
                (states) => FilledButton.foregroundColor(
                  FluentTheme.of(context),
                  states,
                ),
              ),
            ),
          ),
          child: Text(text,
              style: TextStyle(
                  fontSize: 12, color: checked ? Colors.white : Colors.black)),
          checked: checked,
          onChanged: onChanged),
    );
  }
}
